﻿
//********************************************************************************//
//创建日期：<创建日期，2016-4-11>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：加价账单-发票报废
//********************************************************************************//

using BLL.Access;
using System;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui.ShouFeiGL
{
    public partial class JiaJiaZD_FPBF : BasePage
    {


        #region 属性

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtXiangXiXX
        {
            get
            {
                return ViewState["dtXiangXiXX"] as DataTable;
            }
            set
            {
                ViewState["dtXiangXiXX"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 存储过程调用类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();
        #endregion


        #region 事件

        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        /// <summary>
        /// 发票报废
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnBaoFei_Click(object sender, EventArgs e)
        {
            if (txtFaPiaoHM.Text != "" && IsNatural_Number(txtFaPiaoHM.Text))
            {
                DataTable dt = _SpHelper.P_YSSF_FAPIAOBF(txtFaPiaoHM.Text).Tables[0];
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (Convert.ToInt32(dt.Rows[0][0]) > 0)
                    {
                        PageTools.AlertMsg(this, "报废成功！");
                        btnBaoFei.Enabled = false;
                    }
                    else
                    {
                        PageTools.AlertMsg(this, "报废失败！");
                    }
                }
                else
                {
                    PageTools.AlertMsg(this, "此发票已报废！");
                }
                
            }
            else 
            {
                PageTools.AlertMsg(this, "输入条件错误，请重新输入");
            }
            
        }

        /// <summary>
        /// 根据发票号查询相关信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtFaPiaoHM.Text == "")
            {
                PageTools.AlertMsg(this, "发票号码不能为空");
            }
            else
            {
                if (IsNatural_Number(txtFaPiaoHM.Text))
                {
                    this.dtXiangXiXX = _SpHelper.P_YSSF_DDFPDYFYXX(txtFaPiaoHM.Text).Tables[0];
                    if (this.dtXiangXiXX != null && this.dtXiangXiXX.Rows.Count > 0)
                    {
                        //费用编号
                        txtFeiYongBH.Text = this.dtXiangXiXX.Rows[0]["I_FEIYONGBH"].ToString();
                        txtFaPiaoHM2.Text = txtFaPiaoHM.Text;

                        txtYongHuM.Text = this.dtXiangXiXX.Rows[0]["S_YONGHUM"].ToString();
                        txtShuiLiangN.Text = this.dtXiangXiXX.Rows[0]["I_Y"].ToString();
                        txtShuiLiangY.Text = this.dtXiangXiXX.Rows[0]["I_M"].ToString();
                        //银行户名
                        txtYinHangHM.Text = this.dtXiangXiXX.Rows[0]["V_KAIHUHM"].ToString();
                        //计划量
                        txtJiHuaL.Text = this.dtXiangXiXX.Rows[0]["V_PLAN"].ToString();
                        //实用量
                        txtShiYongL.Text = this.dtXiangXiXX.Rows[0]["I_SHIYONGSL"].ToString();
                        //加价量
                        txtJiaJiaL.Text = this.dtXiangXiXX.Rows[0]["I_JIAJIAYSL"].ToString();
                        //实收金额
                        txtShiShouJE.Text = this.dtXiangXiXX.Rows[0]["N_SHISHOUJE"].ToString();
                        //打印日期
                        deDaYinRQ.Text = this.dtXiangXiXX.Rows[0]["D_DAYINRQ"].ToString();

                        btnBaoFei.Enabled = true;
                    }
                    else
                    {
                        PageTools.AlertMsg(this, "此发票已报废或者不存在该发票");
                    }
                }
                else 
                {
                    PageTools.AlertMsg(this, "输入的编号不合符规范，请重新输入");
                }
                
            }
        }

        #endregion


        #region 方法
       
        /// <summary>
        /// 正则表达式验证只能输入数字
        /// </summary>
        /// <param name="pendingString"></param>
        /// <returns></returns>

        private bool IsNatural_Number(string str)
        {
            System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9]*$");
            return reg1.IsMatch(str);
        }

        #endregion

    }

}
